# Contributor: Jeongbin Park <pjb7687@gmail.com>

_realname=cas-offinder
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.4.1
pkgrel=4
pkgdesc='A fast algorithm to search for potential off-target sites of Cas9 RNA-guided endonucleases (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
license=('BSD')
url="https://github.com/snugel/${_realname}"
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-openmp"
         "${MINGW_PACKAGE_PREFIX}-opencl-icd")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-opencl-headers")
source=(${_realname}-${pkgver}.tar.gz::"${url}/archive/${pkgver}.tar.gz")
sha256sums=('b33b9f39c15abae317ddaf6a4d93cd4dd184a73e8437a1a1c2dc75d933531f84')

build() {
  mkdir -p ${srcdir}/build-${MSYSTEM} && cd ${srcdir}/build-${MSYSTEM}

  declare -a _extra_config
  if check_option "debug" "n"; then
    _extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    _extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  ${MINGW_PREFIX}/bin/cmake \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    "${_extra_config[@]}" \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake --build .
}

package() {
  cd ${srcdir}/${_realname}-${pkgver}
  mkdir -p ${pkgdir}${MINGW_PREFIX}/bin/
  cp ${srcdir}/build-${MSYSTEM}/cas-offinder ${pkgdir}${MINGW_PREFIX}/bin/
  mkdir -p ${pkgdir}${MINGW_PREFIX}/share/licenses/$_realname
  cp -pf ${srcdir}/${_realname}-${pkgver}/LICENSE \
    ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}
}
